//
//  JYJVCOfIntroduction.m
//  HappyListen
//
//  Created by 冀永金 on 16/9/2.
//  Copyright © 2016年 冀永金. All rights reserved.
//

#import "JYJVCOfIntroduction.h"
#import "JYJTAMacro.h"
#import "BaseLabel.h"
#import "Masonry.h"
#import "BaseCollectionView.h"
#import "JYJAncCollectionViewCell.h"
#import "JYJIntroductionCollectionViewCell.h"
#import "UIImageView+WebCache.h"
#import "SelfSizeTool.h"
@interface JYJVCOfIntroduction ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property (nonatomic, strong) BaseCollectionView *smallCollection;

@end

@implementation JYJVCOfIntroduction

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"简介";
    self.view.backgroundColor = [UIColor colorWithRed:0.07 green:0.07 blue:0.08 alpha:1.00];
    [self createSubViews];
    [self createSmallCollection];
       // Do any additional setup after loading the view.
}
- (void)setIntoductionDic:(NSDictionary *)intoductionDic {
    _intoductionDic = intoductionDic;
    [self.smallCollection reloadData];
}
- (void)createSubViews {
    UIImageView *imageOfBig = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT * 3 / 5)];
    [self.view addSubview:imageOfBig];
    [imageOfBig sd_setImageWithURL:[NSURL URLWithString:[self.intoductionDic objectForKey:@"item_img"]] placeholderImage:PLACEHOLDERIMAGE];
    BaseLabel *biaoqianLabel = [[BaseLabel alloc]init];
    [self.view addSubview:biaoqianLabel];
    biaoqianLabel.text = @"标签:";
    biaoqianLabel.textColor = [UIColor whiteColor];
    [biaoqianLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imageOfBig.mas_bottom).with.offset(5);
        make.left.equalTo(self.view.mas_left).with.offset(20);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(40);
    }];
    UIView *redView = [[UIView alloc]init];
    [self.view addSubview:redView];
    redView.backgroundColor = [UIColor colorWithRed:0.87 green:0.24 blue:0.18 alpha:1.00];
    [redView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(biaoqianLabel.mas_bottom).with.offset(5);
        make.left.equalTo(self.view.mas_left).with.offset(0);
        make.right.equalTo(self.view.mas_right).with.offset(0);
        make.height.mas_equalTo(2);
    }];
    BaseLabel *jianjieLabel = [[BaseLabel alloc]init];
    [self.view addSubview:jianjieLabel];
    jianjieLabel.text = @"栏目简介:";
    jianjieLabel.textColor = [UIColor whiteColor];
    [jianjieLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(redView.mas_bottom).with.offset(2);
        make.left.equalTo(self.view.mas_left).with.offset(20);
        make.width.mas_equalTo(80);
        make.height.mas_equalTo(30);
    }];
    BaseLabel *textLabel = [[BaseLabel alloc]init];
    [self.view addSubview:textLabel];
    textLabel.textColor = [UIColor whiteColor];
    [textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(jianjieLabel.mas_bottom).with.offset(-5);
        make.left.equalTo(self.view.mas_left).with.offset(20);
        make.right.equalTo(self.view.mas_right).with.offset(-20);
        make.height.mas_equalTo(140);
    }];
    textLabel.numberOfLines = 0;
    textLabel.textAlignment = 0;
    textLabel.text = [self.intoductionDic objectForKey:@"item_desc"];
    textLabel.font = [UIFont systemFontOfSize:15];
    
}
- (void)createSmallCollection {
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
    layout.minimumInteritemSpacing = 10;
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    _smallCollection = [[BaseCollectionView alloc]initWithFrame:CGRectMake(70, SCREEN_HEIGHT * 3 / 5 + 5, SCREEN_WIDTH - 70, 40) collectionViewLayout:layout];
    [self.view addSubview:_smallCollection];
    [self.smallCollection registerClass:[JYJIntroductionCollectionViewCell class] forCellWithReuseIdentifier:@"introduction"];
    self.smallCollection.delegate = self;
    self.smallCollection.dataSource = self;

}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    NSArray *arr = [[self.intoductionDic objectForKey:@"item_tags"] componentsSeparatedByString:@","];
    return arr.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    JYJIntroductionCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"introduction" forIndexPath:indexPath];
    NSString *str = [self.intoductionDic objectForKey:@"item_tags"];
    NSArray *arr = [str componentsSeparatedByString:@","];
    cell.tagLabel.text = arr[indexPath.row];
    return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    NSArray *arr = [[self.intoductionDic objectForKey:@"item_tags"] componentsSeparatedByString:@","];
    NSString *str = arr[indexPath.row];
    CGFloat width = [SelfSizeTool selfSizeWidthString:str height:25 font:[UIFont systemFontOfSize:17]];
    return CGSizeMake(width + 5, 25);
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
